<?php 
defined('LMO') or die('Can\'t access !'); 

class LCUser {
    static $instance;
    
    public static function getInstance()
    {
        if(!isset(self::$instance)) {
            self::$instance = new LCUser();
        }
        
        return self::$instance;
    }
    
    public function indexAction() 
    {
        if(!isset($_SESSION['logged'])) {
            header('location: '.BASE_URL.BS.'index.php?c=user&m=login');
        } else {
            header('location: '.BASE_URL);
        }
    }
    
    public function loginAction()
    {
        if (!isset($_SESSION['logged'])) {
            if(!empty($_POST)) {
                if(isset($_POST['username']) && isset($_POST['password']) && $_POST['username'] == USERNAME && $_POST['password']) {
                    $_SESSION['logged'] = true;
                    header('location:'. BASE_URL);
                }
            }
        } else {
            header('location:'. BASE_URL);
        }
        
        $layout = LLayout::getInstance();
        $html = $layout->assign('login');
        $layout->loadLayout($html);
    }
    
    public function logoutAction()
    {
        session_destroy();
        header('location:'. BASE_URL);
    }
}
?>